//
//  DKMainBankCardController.m
//  DanKU
//
//  Created by 蓝鳍互娱 on 2023/12/1.
//

#import "DKMainBankCardController.h"
#import "DKMainBankCardModifyController.h"
#import "DKBankCardNewController.h"
#import "DKAuthStepViewController.h"
#import "DKUnauthorizedNoRecordView.h"
@interface DKMainBankCardController ()
@property (nonatomic,strong) UILabel * dk_BankCardNameLab;
@property (nonatomic,strong) UILabel * dk_BankCardNoLab;

@property (nonatomic,strong) DKBankCardModel *dk_BankCardMdl;
@end

@implementation DKMainBankCardController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    [self makeNavBack];
    if(![[DKGlobalHelper defaultManager].loanSetpInfoMdl.step isEqualToString:@"100"]){//未认证
        [self creatUnAuthView];
    }else{
        [self dk_addSubView];
        [self getBankCardRequest];
    }
    [DKPublicHttp apiUserBrhavRecordForAPI:@{} withPageName:DK_Bankcard withAction:DK_ActionEnter complete:^{
            
    } fail:^{
            
    }];
}
- (void)dk_addSubView{
    UILabel * dk_BankCardHeadLab = [[UILabel alloc] init];
    dk_BankCardHeadLab.textColor = DK_Hex(@"#333333");
    dk_BankCardHeadLab.font = DK_FONT_Medium(17);
    dk_BankCardHeadLab.text = @"Current bank card";
    [self.view addSubview:dk_BankCardHeadLab];
    [dk_BankCardHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(76)+DK_SafeAreaTop));
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(24)));
    }];
    //银行卡
    UIImageView * dk_BankCardBg = [[UIImageView alloc] init];
    dk_BankCardBg.userInteractionEnabled = YES;
    dk_BankCardBg.image = DK_GetImage(@"dk_MainBankCardBg");
    [self.view addSubview:dk_BankCardBg];
    [dk_BankCardBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dk_BankCardHeadLab.mas_bottom).offset(DK_IsWidthScale(20));
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.right.equalTo(@(-DK_IsWidthScale(15)));
        make.height.equalTo(@(DK_IsWidthScale(165)));
    }];
    self.dk_BankCardNameLab = [[UILabel alloc] init];
    self.dk_BankCardNameLab.textColor = DK_Hex(@"#FFFFFF");
    self.dk_BankCardNameLab.font = DK_FONT_Regular(16);
    self.dk_BankCardNameLab.numberOfLines = 0;
    [dk_BankCardBg addSubview:self.dk_BankCardNameLab];
    [self.dk_BankCardNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(30)));
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(100)));
    }];
    self.dk_BankCardNoLab = [[UILabel alloc] init];
    self.dk_BankCardNoLab.textColor = DK_Hex(@"#FFFFFF");
    self.dk_BankCardNoLab.font = DK_FONT_Regular(20);
    [dk_BankCardBg addSubview:self.dk_BankCardNoLab];
    [self.dk_BankCardNoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.bottom.equalTo(@(-DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(22)));
    }];
    //提示
    UIView * dk_BankCardAlertBgView = [[UIView alloc] init];
    dk_BankCardAlertBgView.backgroundColor = DK_Hex(@"#FAECEC");
    dk_BankCardAlertBgView.layer.cornerRadius = DK_IsWidthScale(10);
    [self.view addSubview:dk_BankCardAlertBgView];
    [dk_BankCardAlertBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dk_BankCardBg.mas_bottom).offset(DK_IsWidthScale(13));
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.right.equalTo(@(-DK_IsWidthScale(15)));
        make.height.equalTo(@(DK_IsWidthScale(60)));
    }];
    UIImageView * dk_BankCardAlertHeadImgView = [[UIImageView alloc] init];
    dk_BankCardAlertHeadImgView.image = DK_GetImage(@"dk_MainBankCardHead");
    dk_BankCardAlertHeadImgView.userInteractionEnabled = YES;
    [dk_BankCardAlertBgView addSubview:dk_BankCardAlertHeadImgView];
    [dk_BankCardAlertHeadImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(dk_BankCardAlertBgView);
        make.left.equalTo(@(DK_IsWidthScale(14)));
        make.width.equalTo(@(DK_IsWidthScale(24)));
        make.height.equalTo(@(DK_IsWidthScale(23)));
    }];
    UILabel * dk_BankCardAlertLab = [[UILabel alloc] init];
    dk_BankCardAlertLab.textColor = DK_Hex(@"#E05353");
    dk_BankCardAlertLab.font = DK_FONT_Regular(10);
    dk_BankCardAlertLab.text = @"We will not ask you for the verification code in any way. For the safety of your funds, please do not give the SMS verification code to anyone.";
    dk_BankCardAlertLab.numberOfLines = 0;
    [dk_BankCardAlertBgView addSubview:dk_BankCardAlertLab];
    [dk_BankCardAlertLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.bottom.equalTo(@(-DK_IsWidthScale(0)));
        make.left.equalTo(@(DK_IsWidthScale(47)));
        make.right.equalTo(@(-DK_IsWidthScale(13)));
    }];
    //协议
    UIButton * dk_AuthPrivacyAgreementBtn = [[UIButton alloc] init];
    [dk_AuthPrivacyAgreementBtn setTitle:@"《Privacy Agreement》" forState:UIControlStateNormal];
    [dk_AuthPrivacyAgreementBtn setTitleColor:DK_Hex(@"#CCCCCC") forState:UIControlStateNormal];
    dk_AuthPrivacyAgreementBtn.titleLabel.font = DK_FONT_Regular(12);
    [dk_AuthPrivacyAgreementBtn addTarget:self action:@selector(checkPrivacyAgreement) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:dk_AuthPrivacyAgreementBtn];
    [dk_AuthPrivacyAgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(@(-DK_IsWidthScale(80)-DK_SafeAreaBottom));
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
    //next
    UIButton *dk_AuthModifyBtn  = [[UIButton alloc] init];
    [dk_AuthModifyBtn setTitle:@"To modify" forState:UIControlStateNormal];
    [dk_AuthModifyBtn setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
    dk_AuthModifyBtn.titleLabel.font = DK_FONT_Semibold(16);
    [dk_AuthModifyBtn setBackgroundImage:DK_GetImage(@"dk_registerNextSelectBg") forState:UIControlStateNormal];
    [dk_AuthModifyBtn addTarget:self action:@selector(goModify) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:dk_AuthModifyBtn];
    [dk_AuthModifyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.bottom.equalTo(dk_AuthPrivacyAgreementBtn.mas_top).offset(-DK_IsWidthScale(20));
    }];
}
- (void)creatUnAuthView{
    DKUnauthorizedNoRecordView * dkUnauthorizedNoRecordView = [[DKUnauthorizedNoRecordView alloc] init];
    [self.view addSubview:dkUnauthorizedNoRecordView];
    [dkUnauthorizedNoRecordView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(114)+DK_SafeAreaTop));
        make.height.equalTo(@(DK_IsWidthScale(148)));
    }];
    UIButton * dk_LoanApplyBtn = [[UIButton alloc] init];
    [dk_LoanApplyBtn setTitle:@"Apply now" forState:UIControlStateNormal];
    [dk_LoanApplyBtn setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
    dk_LoanApplyBtn.titleLabel.font = DK_FONT_Medium(16);
    [dk_LoanApplyBtn setBackgroundImage:DK_GetImage(@"dk_registerNextSelectBg") forState:UIControlStateNormal];
    [dk_LoanApplyBtn addTarget:self action:@selector(goLoanApply) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:dk_LoanApplyBtn];
    [dk_LoanApplyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(30)));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.height.equalTo(@(DK_IsWidthScale(50)));
        make.bottom.equalTo(@(-DK_IsWidthScale(194)-DK_SafeAreaBottom));
    }];
    UIButton * dk_LoanApplyAgreementBtn = [[UIButton alloc] init];
    [dk_LoanApplyAgreementBtn setTitle:@"《Privacy Agreement》" forState:UIControlStateNormal];
    [dk_LoanApplyAgreementBtn setTitleColor:DK_Hex(@"#CCCCCC") forState:UIControlStateNormal];
    dk_LoanApplyAgreementBtn.titleLabel.font = DK_FONT_Regular(12);
    [dk_LoanApplyAgreementBtn addTarget:self action:@selector(checkPrivacyAgreement) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:dk_LoanApplyAgreementBtn];
    [dk_LoanApplyAgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(dk_LoanApplyBtn.mas_bottom).offset(DK_IsWidthScale(97));
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
}
- (void)goLoanApply{
    DKAuthStepViewController *dk_AuthStepViewCtrl = [[DKAuthStepViewController alloc] init];
    dk_AuthStepViewCtrl.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:dk_AuthStepViewCtrl animated:YES];
}
- (void)getBankCardRequest{
    WeakSelf(self)
    [DKPublicHttp apiGetBankCardListForAPI:@{} complete:^(NSArray * _Nonnull bankCardMdls) {
        if(bankCardMdls.count > 0){
            DKBankCardModel *dk_BankCardMdl = bankCardMdls.firstObject;
            if(dk_BankCardMdl.data.length){
                dk_BankCardMdl.bankCardInfo = [DKBankCardInfoModel mj_objectWithKeyValues:dk_BankCardMdl.data.mj_JSONObject];
                weakSelf.dk_BankCardMdl = dk_BankCardMdl;
                [weakSelf makeBankCardData];
            }
        }
        
    }];
}
- (void)makeBankCardData{
    if(self.dk_BankCardMdl){
        self.dk_BankCardNameLab.text = self.dk_BankCardMdl.bankCardInfo.bankName;
        self.dk_BankCardNoLab.text = self.dk_BankCardMdl.bankCardInfo.bankCard;
    }
}
- (void)goModify{
    DKBankCardNewController *bankCardNewCtrl = [[DKBankCardNewController alloc] init];
    [self.navigationController pushViewController:bankCardNewCtrl animated:YES];
//    DKMainBankCardModifyController *dk_MainBankCardModifyCtrl = [[DKMainBankCardModifyController alloc] init];
//    dk_MainBankCardModifyCtrl.dk_BankCardMdl = self.dk_BankCardMdl;
//    [self.navigationController pushViewController:dk_MainBankCardModifyCtrl animated:YES];
}
- (void)checkPrivacyAgreement{
    DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
    [self.navigationController pushViewController:dk_WebViewCtrl animated:YES];
}
@end
